<?php
session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';

}

//query po table tblcms cms  type

	$flag	= false;
	$type	= '';
	if (isset ($_GET['type'])) {
		$type	= $_GET['type'];
		$flag	= true;
	}	

	if ($flag) {
		$cmsId = $_GET['cmsid'];
    
		
		if ($type == 1) {
			$status	= "on";
			
			$q			= "	UPDATE 	tblcms 
						SET		cmsStatus = '".$status."' 
						WHERE	cmsId 	= '".$cmsId."' ";	
							
		$update		= mysql_query($q);
		   
		} else {
			$status	= "off";	
			$q			= "	UPDATE 	tblcms 
						SET		cmsStatus = '".$status."' 
						WHERE	cmsId 	= '".$cmsId."' ";	
							
		$update		= mysql_query($q);
		   	
		}
		
		
		
		print("<script>");
			if ($update) { 
				if($status == 'off'){
				print("alert('Page has been unpublish!');"); 
				print 'window.history.go(-1)';}
				elseif($status == 'on'){
				print("alert('Page has been publish!');");
				print 'window.history.go(-1)';
				}
			} else {
				print("alert('Cannot save');");
				print 'window.history.go(-1)';
			}
		print("</script>");

	}
?>

